<!-- http://bootstrap-table.wenzhixin.net.cn/zh-cn/documentation/#表格参数 -->
<!-- https://blog.csdn.net/javahighness/article/details/73929108 -->
<!-- http://issues.wenzhixin.net.cn/bootstrap-table/#methods/getSelections.html -->

<!-- 导出不适合父子表，不能导出父子关系 -->
<!-- 可以ajax请求数据 -->


<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>Bootstrap 实例 - 标签页（Tab）插件</title>
	<link rel="stylesheet" href="script/bootstrap-3.3.7.min.css">
	  <script src="script/jquery-1.10.min.js"></script>
	<script src="script/bootstrap-3.3.7.min.js"></script>
		<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<link href="script/bootstrap-table.min.css" rel="stylesheet" media="screen">
<script src="script/bootstrap-table.min.js" type="text/javascript"></script>
    <script src="script/bootstrap-table-zh-CN.min.js" charset="UTF-8" type="text/javascript"></script>

</head>
<body>
<button class="btn btn-default" id="get_table_data">导出数据</button> 
<!-- 返回表格数据 -->



<table id="tb" class="tabletable-striped table_list" style="border-top:1px solid #cecece ;margin:10px 10px 15px 0px;">

<!-- <th>序号</th>
<th>任务名称</th>
<th>任务标签</th>
<th>创建用户</th>
<th>统计次数</th>
<th>应用名称</th>
<th>创建时间</th>
<th>修改时间</th>

 -->
</table>

</body>
<script type="text/javascript">
    var json_data_ex= {"data": [{"name": "测试1", "tag": "\u6d4b\u8bd5\u4efb\u52a1\u6807\u7b7e", "create_user": "org", "total_run_count": 36, "create_time": "2018-06-04-15:19", "app_list": [{'name':'sub1','time':2018}], "id": 7, "last_run_time": "2018-06-05 10:23"},
      {"name": "测试2", "tag": "\u6d4b\u8bd5\u4efb\u52a1\u6807\u7b7e", "create_user": "org", "total_run_count": 36, "create_time": "2018-06-04-15:19", "app_list": [{'name':'sub2','time':2018}], "id": 7, "last_run_time": "2018-06-05 10:23"},
      {"name": "测试2", "tag": "\u6d4b\u8bd5\u4efb\u52a1\u6807\u7b7e", "create_user": "org", "total_run_count": 36, "create_time": "2018-06-04-15:19", "id": 7, "last_run_time": "2018-06-05 10:23"}], "success": true}


$(function() {

$("#get_table_data").on("click",function(){
   var data = $('#tb').bootstrapTable('getAllSelections');
   console.log(data)

  var oTableInit = {}; //jquery 方式定义

   $('#tb').bootstrapTable('destroy').bootstrapTable({
      data : json_data_ex.data,

      // data: [

      //     { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 35},

      // ],
      clickToSelect : true, //设置true 将在点击行时，自动选择rediobox 和 checkbox
      search : true,
      paginationPreText: '<', //上下翻页

        paginationNextText: '>',

      detailView: true, //父子表

      striped: true, //是否显示行间隔色

      pagination: true, //是否显示分页（*）

      sortOrder: "asc", //排序方式

      pageNumber: 1, //初始化加载第一页，默认第一页

      // height: 800,     默认高度

      pageSize: 10, //每页的记录行数（*）

      pageList: [10, 20], //可供选择的每页的行数（*）

      columns: [
                {
                    checkbox: true, // 显示一个勾选框
                    align: 'center' // 居中显示
                },
               {

                  title: "序号",

                  formatter: function(value, row, index) {

                     return index + 1;

                  },

                  rowspan: 1,

                  align: 'center',

                  width: '50px'

               },{

            field: 'id',

            title: 'id',
            visible: false, //不显示

            // align: 'left',

         },
               {

            field: 'name',

            title: '名称',

            align: 'left',

         }, {

            field: 'tag',

            title: '标签',

            align: 'left',

         }, {

            field: 'create_user',

            title: '创建用户',

            align: 'center',

            

         }, {

            field: 'total_run_count',

            title: '次数',   

            align: 'right',

         },{
            field: 'create_time',

            title: '创建时间',   

            align: 'right',
         }

      ],

      onExpandRow: function(index, row, $detail) {

         oTableInit.InitSubTable(index, row, $detail);
// index：父表当前行的行索引。

// row：父表当前行的Json数据对象。

// $detail：当前行下面创建的新行里面的td对象,子表对象
      }

   });



oTableInit.InitSubTable = function(index, row, $detail) {

   var cur_table = $detail.html('<table></table>').find('table'); //find jquery遍历 table

   $(cur_table).bootstrapTable({

      data : row.app_list,
      // data: [{ "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 503, "time": "34.65", "matter": '98.05' },

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 503, "time": "34.65", "matter": '98.05' },

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 503, "time": "34.65", "matter": '98.05' },

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 503, "time": "34.65", "matter": '98.05' },

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 503, "time": "34.65", "matter": '98.05' },

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 503, "time": "34.65", "matter": '98.05' },

      //    { "no": "FF21135", "type": "生产单元一", "name": "PVHI", "money": 503, "time": "34.65", "matter": '98.05' },

      // ],

      method: 'get',

      // queryParams: { strParentID: parentid },

      // ajaxOptions: { strParentID: parentid },

      queryParams: { strParentID: 2 },

      ajaxOptions: { strParentID: 1 },
      clickToSelect: true,

      pagination: true, //是否显示分页（*）

      sortOrder: "asc", //排序方式

      pageNumber: 1, //初始化加载第一页，默认第一页

      // height: 260,

      pageSize: 6, //每页的记录行数（*）

      pageList: [6, 12, 24, 48], //可供选择的每页的行数（*）

        paginationPreText: '<', //上下翻页

        paginationNextText: '>',

      columns: [
               {
                    checkbox: true, // 显示一个勾选框
                    align: 'center' // 居中显示
                },
               {

                  title: "序号",

                  formatter: function(value, row, index) {

                     return index + 1;

                  },

                  rowspan: 1,

                  align: 'center',

                  width: '50px'

               },{

            field: 'name',

            title: '应用名',

            align: 'left',

         }, {

            field: 'time',

            title: '创建时间',

            align: 'left',

         }

      ],

      //无线循环取子表，直到子表里面没有记录

      onExpandRow: function(index, row, $Subdetail) {

         oInit.InitSubTable(index, row, $Subdetail);

      }

   });

   return oTableInit; 

};

});

</script>

</html>